<template>
	<div class="step1">
		<ul class="uls">
			<li class="lis">
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.managementFullName">
						<el-form slot="reference">
							<el-form-item label="管理人名称" required>
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('managementId', '管理人名称', 'organInfo')">(未复核)</span>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-select
						v-model="organInfo.managementId"
						:value="`aasd`"
						filterable
						clearable
						placeholder="请选择"
						:disabled="isBaseDisabled"
						@change="changeManagementId"
					>
						<el-option value="" label="--请选择--"></el-option>
						<el-option
							v-for="(item, index) in managementList"
							:key="index + 'manId'"
							:label="item.managementFullName"
							:value="item.managementId"
						></el-option>
					</el-select>
					<div class="blurmsg" v-if="isCheck && !!!organInfo.managementId">请选择管理人名称</div>
				</div>
				<div class="div2">
					<el-popover
						placement="top-start"
						width="200"
						trigger="hover"
						:content="$store.getters.hoverPerty.organInfo.managementRegisterNumber"
					>
						<el-form slot="reference"><el-form-item label="管理人代码" required></el-form-item></el-form>
					</el-popover>
				</div>
				<div class="div2">
					{{ organRelationInfo.managementRegisterNumber }}
				</div>
			</li>

			<li class="lis">
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.fundTaTypeName">
						<el-form slot="reference">
							<el-form-item label="登记机构名称">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('fundTaType', '登记机构名称', 'organInfo')">(未复核)</span>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-select
						v-model="organInfo.fundTaType"
						filterable
						clearable
						placeholder="请选择"
						:disabled="isBaseDisabled"
						@change="changeFundTaTypeCode"
					>
						<el-option value="" label="--请选择--"></el-option>
						<el-option
							v-for="(item, index) in fundTaTypeList"
							:key="item.typeCode + index"
							:label="item.typeName"
							:value="item.typeCode"
						></el-option>
					</el-select>
				</div>
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.fundTaType">
						<el-form slot="reference">
							<el-form-item label="登记机构代码"> </el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					{{ organInfo.fundTaType }}
				</div>
			</li>

			<li class="lis">
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.isThirdPartyCustody">
						<el-form slot="reference">
							<el-form-item label="是否第三方托管" required>
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('isThirdPartyCustody', '是否第三方托管', 'organInfo')"
										>(未复核)</span
									>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div3">
					<el-radio-group v-model="organInfo.isThirdPartyCustody" :disabled="isBaseDisabled" @change="focusUpdate">
						<el-radio label="0">是</el-radio>
						<el-radio label="1">否</el-radio>
					</el-radio-group>
					<div class="blurmsg" v-if="isCheck && !!!organInfo.isThirdPartyCustody">请选择是否第三方托管</div>
				</div>
			</li>

			<li class="lis">
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.trusteeFullName">
						<el-form slot="reference">
							<el-form-item label="托管人名称">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('trusteeId', '托管人名称', 'organInfo')">(未复核)</span>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-select
						v-model="organInfo.trusteeId"
						filterable
						clearable
						placeholder="请选择"
						:disabled="isBaseDisabled"
						@change="changeCustodianId"
					>
						<el-option value="" label="--请选择--"></el-option>
						<el-option
							v-for="(item, index) in custodianList"
							:key="index + 'tuoguan'"
							:label="item.trusteeFullName"
							:value="item.trusteeId"
						></el-option>
					</el-select>
				</div>
				<div class="div2">
					<el-popover
						placement="top-start"
						width="200"
						trigger="hover"
						:content="$store.getters.hoverPerty.organInfo.trusteeRegisterNumber"
					>
						<el-form slot="reference"><el-form-item label="托管人代码"></el-form-item></el-form>
					</el-popover>
				</div>
				<div class="div2">
					{{ organRelationInfo.trusteeRegisterNumber }}
				</div>
			</li>

			<li class="lis">
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.iscustodyBranchOrgan">
						<el-form slot="reference">
							<el-form-item label="是否有托管分支机构">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('iscustodyBranchOrgan', '是否有托管分支机构', 'organInfo')"
										>(未复核)</span
									>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-radio-group
						v-model="organInfo.iscustodyBranchOrgan"
						:disabled="isBaseDisabled"
						@change="organInfo.iscustodyBranchOrgan == '1' ? (organInfo.custodyBranchOrganName = '') : ''"
					>
						<el-radio label="0">有</el-radio>
						<el-radio label="1">无</el-radio>
					</el-radio-group>
				</div>
				<div class="div2">
					<el-popover
						placement="top-start"
						width="200"
						trigger="hover"
						:content="$store.getters.hoverPerty.organInfo.custodyBranchOrganName"
					>
						<el-form slot="reference">
							<el-form-item label="托管人分支机构名称" :required="organInfo.iscustodyBranchOrgan === '0'">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('custodyBranchOrganName', '托管人分支机构名称', 'organInfo')"
										>(未复核)</span
									>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-input v-model="organInfo.custodyBranchOrganName" :disabled="isBaseDisabled" @input="focusUpdate"></el-input>
					<div class="blurmsg" v-if="isCheck && !!!organInfo.custodyBranchOrganName && organInfo.iscustodyBranchOrgan === '0'">
						请输入托管人分支机构名称
					</div>
				</div>
			</li>

			<li class="lis">
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.investAdvisorName">
						<el-form slot="reference">
							<el-form-item label="投资顾问中文名称">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('investAdvisorId', '投资顾问中文名称', 'organInfo')">(未复核)</span>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-select
						v-model="organInfo.investAdvisorId"
						filterable
						clearable
						placeholder="请选择"
						:disabled="isBaseDisabled"
						@change="changeInvestAdvisorId"
					>
						<el-option value="" label="--请选择--"></el-option>
						<el-option
							v-for="(item, index) in investAdvisorList"
							:key="index + 'guwen'"
							:label="item.investAdvisorName"
							:value="item.investAdvisorId"
						></el-option>
					</el-select>
				</div>
				<div class="div4">
					<div class="div4child">
						<div class="div4childlitem1">
							<el-popover
								placement="top-start"
								width="200"
								trigger="hover"
								:content="$store.getters.hoverPerty.organInfo.advisorRegisterNumber"
							>
								<el-form slot="reference">
									<el-form-item label="投资顾问代码"> </el-form-item>
								</el-form>
							</el-popover>
						</div>
						<div class="div4childlitem2">
							{{ organRelationInfo.advisorRegisterNumber }}
						</div>
					</div>
					<div class="div4child" style="border: none">
						<div class="div4childlitem1">
							<el-popover
								placement="top-start"
								width="200"
								trigger="hover"
								:content="$store.getters.hoverPerty.organInfo.advisorEnglishName"
							>
								<el-form slot="reference"><el-form-item label="投资顾问英文名称"></el-form-item></el-form>
							</el-popover>
						</div>
						<div class="div4childlitem2">
							{{ organRelationInfo.advisorEnglishName }}
						</div>
					</div>
				</div>
			</li>

			<li class="lis">
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.lawFirmName">
						<el-form slot="reference">
							<el-form-item label="律师事务所名称">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('lawId', '律师事务所名称', 'organInfo')">(未复核)</span>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-select
						class="tdTop2"
						v-model="organInfo.lawId"
						filterable
						clearable
						placeholder="请选择"
						:disabled="isBaseDisabled"
						@change="changeLawFirmId"
					>
						<el-option value="" label="--请选择--"></el-option>
						<el-option
							v-for="(item, index) in lawFirmList"
							:key="index + 'lvshi'"
							:label="item.lawFirmName"
							:value="item.lawFirmId"
						></el-option>
					</el-select>
				</div>
				<div class="div4">
					<div class="div4child">
						<div class="div4childlitem1">
							<el-popover
								placement="top-start"
								width="200"
								trigger="hover"
								:content="$store.getters.hoverPerty.organInfo.lawFirmRegisterNumber"
							>
								<el-form slot="reference"><el-form-item label="律师事务所代码"></el-form-item></el-form>
							</el-popover>
						</div>
						<div class="div4childlitem2">
							{{ organRelationInfo.lawFirmRegisterNumber }}
						</div>
					</div>
					<div class="div4child" style="border: none">
						<div class="div4childlitem1">
							<el-popover
								placement="top-start"
								width="200"
								trigger="hover"
								:content="$store.getters.hoverPerty.organInfo.handleLawerName"
							>
								<el-form slot="reference">
									<el-form-item label="经办律师名称">
										<span v-if="['6'].includes(dataType)">
											<span style="color: red" v-if="publicCompare('handleLawerName', '经办律师名称', 'organInfo')"
												>(未复核)</span
											>
										</span>
									</el-form-item>
								</el-form>
							</el-popover>
						</div>
						<div class="div4childlitem2">
							<el-input v-model="organInfo.handleLawerName" @input="focusUpdate" :disabled="isBaseDisabled"></el-input>
						</div>
					</div>
				</div>
			</li>

			<li class="lis">
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.accountFirmName">
						<el-form slot="reference">
							<el-form-item label="会计师事务所名称">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('accountFirmId', '会计师事务所名称', 'organInfo')">(未复核)</span>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-select
						v-model="organInfo.accountFirmId"
						filterable
						clearable
						placeholder="请选择"
						:disabled="isBaseDisabled"
						@change="changeAccountingFirmId"
					>
						<el-option value="" label="--请选择--"></el-option>
						<el-option
							v-for="(item, index) in accountingFirmList"
							:key="index + 'kuaiji'"
							:label="item.accountFirmName"
							:value="item.accountFirmId"
						></el-option>
					</el-select>
				</div>
				<div class="div2">
					<el-popover
						placement="top-start"
						width="200"
						trigger="hover"
						:content="$store.getters.hoverPerty.organInfo.accountFirmRegisterNumber"
					>
						<el-form slot="reference"><el-form-item label="会计师事务所代码"></el-form-item></el-form>
					</el-popover>
				</div>
				<div class="div2">
					{{ organRelationInfo.accountFirmRegisterNumber }}
				</div>
			</li>

			<li class="lis">
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.bordersCustodianName">
						<el-form slot="reference">
							<el-form-item label="境外托管人中文名称">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('bordersCustodianName', '境外托管人中文名称', 'organInfo')"
										>(未复核)</span
									>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-input v-model="organInfo.bordersCustodianName" @input="focusUpdate" :disabled="isBaseDisabled"></el-input>
				</div>
				<div class="div2">
					<el-popover
						placement="top-start"
						width="200"
						trigger="hover"
						:content="$store.getters.hoverPerty.organInfo.bordersCustodianEnglishName"
					>
						<el-form slot="reference">
							<el-form-item label="境外托管人英文名称">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('bordersCustodianEnglishName', '境外托管人英文名称', 'organInfo')"
										>(未复核)</span
									>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-input v-model="organInfo.bordersCustodianEnglishName" @input="focusUpdate" :disabled="isBaseDisabled"></el-input>
				</div>
			</li>

			<li class="lis">
				<div class="div2">
					<el-popover placement="top-start" width="200" trigger="hover" :content="$store.getters.hoverPerty.organInfo.bordersAdvisorName">
						<el-form slot="reference">
							<el-form-item label="境外投资顾问中文名称">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('bordersAdvisorName', '境外投资顾问中文名称', 'organInfo')"
										>(未复核)</span
									>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-input v-model="organInfo.bordersAdvisorName" @input="focusUpdate" :disabled="isBaseDisabled"></el-input>
				</div>
				<div class="div2">
					<el-popover
						placement="top-start"
						width="200"
						trigger="hover"
						:content="$store.getters.hoverPerty.organInfo.bordersAdvisorEnglishName"
					>
						<el-form slot="reference">
							<el-form-item label="境外投资顾问英文名称">
								<span v-if="['6'].includes(dataType)">
									<span style="color: red" v-if="publicCompare('bordersAdvisorEnglishName', '境外投资顾问英文名称', 'organInfo')"
										>(未复核)</span
									>
								</span>
							</el-form-item>
						</el-form>
					</el-popover>
				</div>
				<div class="div2">
					<el-input v-model="organInfo.bordersAdvisorEnglishName" @input="focusUpdate" :disabled="isBaseDisabled"></el-input>
				</div>
			</li>
		</ul>
	</div>
</template>
<script>
import { getManagementList, getCustodianList, getInvestAdvisort, getLawFirmList, getAccFirmList, saveOrgan } from '@/api/productApi/infoMain'
import { getEnum, jsonArray } from '@/api/productApi/file'
import { publicCompare } from '@/views/infoMain/publicList/components/dataCheck'
import { defalutOrganInfo } from '../../default'
import { iorganInfoReview } from '@/views/infoMain/publicList/components/dataReview'
export default {
	props: {
		setpFunc: {
			type: Function,
			default: Function
		},
		fundSysCode: {
			type: String,
			default: ''
		},
		dataType: {
			type: String,
			default: ''
		},
		haveYouWalked: {
			type: Object,
			default: Object
		}
	},
	data() {
		return {
			organInfo: {
				handleLawerName: ''
			},
			isBaseDisabled: false,
			organBase: {}, // 机构信息页面对比主表信息
			managementList: [], // 管理人信息
			custodianList: [], // 托管人信息
			lawFirmList: [], // 律师事务所信息
			accountingFirmList: [], // 会计事务所信息
			investAdvisorList: [], // 投资顾问信息
			fundTaTypeList: [], // 登记机构信息
			organRelationInfo: {},
			isCheck: false,
			publicCompare
		}
	},
	mounted() {
		this.getOrganRelationList()
		this.custodianListData()
		this.fundTaTypeListData()
		this.getInvestAdvisortFunc()
		this.getLawFirmListFunc()
		this.getAccFirmListFunc()
	},
	methods: {
		focusUpdate(property) {
			this.$forceUpdate()
		},

		// 重新申请将数据集中在store
		updateStoreData() {
			this.$store.state.fundStep.pucliktTotalData.productFundApply.organInfo = jsonArray(this.organInfo)
		},

		// 完善信息切换步骤时保存切换前页面数据
		async switchingSteps() {
			const params = {}
			params.productFundApply = {}
			params.productFundApply.organInfo = this.organInfo
			params.fundRaiseType = '1'
			params.fundSysCode = this.fundSysCode
			await saveOrgan(params).then(res => {
				if (res.msgCode === 'Y') {
					this.$emit('setpFunc', '1', this.fundSysCode, '', 1)
				}
			})
			return true
		},

		ValidationRequired() {
			return iorganInfoReview(this.organInfo)
		},

		// 新增:【保存】和【下一步】
		startDown(type) {
			this.isCheck = true
			this.CustomtextComfirm(() => {
				const params = {}
				params.productFundApply = {}
				params.productFundApply.organInfo = this.organInfo
				params.fundRaiseType = '1'
				params.fundSysCode = this.fundSysCode
				saveOrgan(params).then(res => {
					if (res.msgCode === 'Y') {
						if (type === '下一步') {
							this.$emit('setpFunc', '1', this.fundSysCode, '', 0)
						} else {
							this.$emit('setpFunc', '1', this.fundSysCode, '', 1)
						}
						this.$message({ type: 'success', message: res.msg })
					}
				})
			}, `${!iorganInfoReview(this.organInfo).length ? '此操作将永久提交已编辑数据，是否继续' : `必填项 “ ${iorganInfoReview(this.organInfo).join('、')} ” 未填写，是否确认提交`}？`)
		},

		isBaseDisabledCom(data, msgShow) {
			this.isBaseDisabled = data
			this.isCheck = msgShow
		},

		async edit(data) {
			await this.getOrganRelationList()
			this.organInfo = JSON.parse(JSON.stringify(data))
			this.changeManagementId()
			this.changeCustodianId()
			this.changeFundTaTypeCode()
			this.changeAccountingFirmId()
			this.changeInvestAdvisorId()
			if (data.lawId) {
				const obj = this.lawFirmList.filter(item => item.lawFirmId === data.lawId)
				this.organRelationInfo.lawFirmRegisterNumber = obj.length ? obj[0].lawFirmRegisterNumber : ''
			}
			this.defaultValue()
		},

		defaultValue() {
			// 当非查看状态时，赋值默认值
			this.$nextTick(() => {
				if ((this.dataType === '1' || this.dataType === '') && !this.haveYouWalked.organMode) {
					defalutOrganInfo.forEach(item => {
						if (!this.organInfo[item.key]) {
							this.$set(this.organInfo, item.key, item.value)
						}
					})
					// 管理人设置默认值
					if (!this.organInfo.managementId) {
						this.managementList.forEach(item => {
							if (item.managementFullName === '景顺长城基金管理有限公司') {
								this.$set(this.organInfo, 'managementId', item.managementId)
							}
						})
					}
				}
			})
		},

		// 改变管理人名称时，改变管理人代码的值
		changeManagementId() {
			if (this.managementList.length) {
				const obj = this.managementList.filter(item => item.managementId === this.organInfo.managementId)
				this.organRelationInfo.managementRegisterNumber = obj.length ? obj[0].managementRegisterNumber : ''
			}
		},

		// 改变托管人名称时，改变托管人代码的值
		changeCustodianId() {
			if (this.custodianList.length) {
				const obj = this.custodianList.filter(item => item.trusteeId === this.organInfo.trusteeId)
				this.organRelationInfo.trusteeRegisterNumber = obj.length ? obj[0].trusteeRegisterNumber : ''
				// this.organInfo.custodyBranchOrganName = obj.length?obj[0].trusteeFullName:''
			}
		},

		// 改变登记机构名称时，改变登记机构代码的值
		changeFundTaTypeCode() {
			if (this.fundTaTypeList.length) {
				const obj = this.fundTaTypeList.filter(item => item.fundTaType === this.organInfo.fundTaType)
				this.organRelationInfo.fundTaTypeCode = obj.length ? obj[0].fundTaTypeCode : ''
			}
		},

		// 改变律师事务所名称时，改变律师事务所代码和经办律师名称的值
		changeLawFirmId() {
			if (this.lawFirmList.length) {
				const obj = this.lawFirmList.filter(item => item.lawFirmId === this.organInfo.lawId)
				this.organRelationInfo.lawFirmRegisterNumber = obj.length ? obj[0].lawFirmRegisterNumber : ''
				this.$set(this.organInfo, 'handleLawerName', obj.length ? obj[0].handleLawerName : '')
			}
			this.$forceUpdate(this.organInfo)
		},

		// 改变会计师事务所名称时，改变会计师事务所代码的值
		changeAccountingFirmId() {
			if (this.accountingFirmList.length) {
				const obj = this.accountingFirmList.filter(item => item.accountFirmId === this.organInfo.accountFirmId)
				this.organRelationInfo.accountFirmRegisterNumber = obj.length ? obj[0].accountFirmRegisterNumber : ''
			}
		},

		// 改变投资顾问中文名称时，改变投资顾问代码和投资顾问英文名称的值
		changeInvestAdvisorId() {
			if (this.investAdvisorList.length) {
				const obj = this.investAdvisorList.filter(item => item.investAdvisorId === this.organInfo.investAdvisorId)
				this.organRelationInfo.advisorRegisterNumber = obj.length ? obj[0].advisorRegisterNumber : ''
				this.organRelationInfo.advisorEnglishName = obj.length ? obj[0].advisorEnglishName : ''
			}
		},

		fundTaTypeListData() {
			// 登记机构
			getEnum(['fundTaType']).then(res => {
				if (res.msgCode === 'Y') {
					this.fundTaTypeList = res.data.body.fundTaType
					this.changeFundTaTypeCode()
				}
			})
		},

		custodianListData() {
			// 托管人
			getCustodianList().then(res => {
				if (res.msgCode === 'Y') {
					this.custodianList = res.data.body
					this.changeCustodianId()
				}
			})
		},

		getInvestAdvisortFunc() {
			// 投资顾问
			getInvestAdvisort().then(res => {
				if (res.msgCode === 'Y') {
					this.investAdvisorList = res.data.body
					this.changeInvestAdvisorId()
				}
			})
		},

		getAccFirmListFunc() {
			// 会计师事务所
			getAccFirmList().then(res => {
				if (res.msgCode === 'Y') {
					this.accountingFirmList = res.data.body
					// 会计师事务所代码赋值
					this.changeAccountingFirmId()
				}
			})
		},

		getLawFirmListFunc() {
			// 律师事务所
			getLawFirmList().then(res => {
				if (res.msgCode === 'Y') {
					this.lawFirmList = res.data.body
					this.changeLawFirmId()
				}
			})
		},

		// 查询：机构相关联列表信息（管理人信息，托管人信息，律师事务所信息，会计事务所信息，投资顾问信息，登记机构信息）
		async getOrganRelationList() {
			await getManagementList().then(res => {
				if (res.msgCode === 'Y') {
					res.data = res.data.body
					// 管理人信息
					this.managementList = res.data
					// 管理人代码赋值
					this.changeManagementId()
				}
			})
		}
	}
}
</script>
<style lang="scss" scoped >
</style>
